package src.dual_pointers;

import java.util.Stack;

/**
 * @author starsea
 * @date 2024-09-09 23:11
 */

public class Test15 {
    public String removeDuplicates(String s) {
        Stack<Character> stack=new Stack<>();
        StringBuffer buffer=new StringBuffer();
        for(char ch: s.toCharArray())
        {
            if(stack.isEmpty())
            {
                stack.push(ch);
                buffer.append(ch);
            }else if(stack.peek()==ch)
            {
                stack.pop();
                buffer.deleteCharAt(buffer.length()-1);
            }else
            {
                stack.push(ch);
                buffer.append(ch);
            }
        }
        return buffer.toString();
    }
}
